<html>

<body>
  <script>
    // Based on: https://manfredsteyer.github.io/angular-oauth2-oidc/docs/additional-documentation/silent-refresh.html

    const checks = [/[\?|&|#]code=/, /[\?|&|#]error=/, /[\?|&|#]token=/, /[\?|&|#]id_token=/];

    function isResponse(str) {
      let count = 0;

      if (!str) {
        return false;
      }

      for (let i = 0; i < checks.length; i++) {
        if (str.match(checks[i])) return true;
      }

      return false;
    }

    let message = isResponse(location.hash) ? location.hash : '#' + location.search;

    console.log("Silent refresh iframe is posting to the parent application, message:", message);

    (window.opener || window.parent).postMessage(message, location.origin);
  </script>
</body>

</html>
